package com.lost.octopus.es.processor.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lost.octopus.es.helper.annotation.EsDocument;
import com.sunsharing.share.boot.framework.annotation.ShareCode;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;
import org.springframework.data.elasticsearch.annotations.Setting;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_HYZT;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_JZYY;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_MZ;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_RYLB;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_XB;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_YHZGX;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_ZJLX;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_ZY;
import static com.lost.octopus.es.processor.constant.DmConstant.DM_RK_ZZYY;
import static org.springframework.data.elasticsearch.annotations.FieldType.Keyword;

/**
 * ES 里的 居民信息
 * @author fxxk
 */
@Data
@Document(indexName = "resident")
@EsDocument(indexName = "tag-resident")
@Setting(
    settingPath = "esSetting.json"
)
public class Resident implements Serializable, IdEntity<Integer> {

    private static final long serialVersionUID = -8678615010586101752L;
    @Id
    private Integer id;

    /**
     * 证件类型 DM_RK_ZJLX
     * T_RK.ZJLX
     */
    @ShareCode(DM_RK_ZJLX)
    @Field(type = Keyword)
    private String idType;
    /**
     * 证件号码
     * T_RK.ZJHM
     */
    @Field(type = Keyword)
    private String idNumber;
    /**
     * 姓名
     * T_RK.XM
     */
    @Field(type = Keyword)
    private String name;
    /**
     * 手机号码
     */
    @Field(type = Keyword)
    private String tel;
    /**
     * 性别 DM_RK_XB
     * T_RK.XB
     */
    @ShareCode(DM_RK_XB)
    @Field(type = Keyword)
    private String gender;

    /**
     * 英文姓
     */
    @Field(type = Keyword)
    private String ywx;

    /**
     * 英文名
     */
    @Field(type = Keyword)
    private String ywm;

    /**
     * 人员类别-DM_RK_RYLB
     */
    @Field(type = Keyword)
    @ShareCode(DM_RK_RYLB)
    private String rylb;

    /**
     * 居住社区 DM_XZQH_DS
     */
    @Field(type = Keyword)
    private String communitys;

    /**
     * 民族 DM_RK_MZ
     * T_RK.MZ
     */
    @ShareCode(DM_RK_MZ)
    @Field(type = Keyword)
    private String nation;

    /**
     * 国籍-DM_RK_GJ
     */
    @Field(type = Keyword)
    private String gj;

    /**
     * 境外人员类型-DM_RK_JWRYLX
     */
    @Field(type = Keyword)
    private String jwrylx;

    /**
     * 监护人1姓名
     */
    @Field(type = Keyword)
    private String jhr1Xm;

    /**
     * 与监护人1关系-DM_RK_RYGX
     */
    @Field(type = Keyword)
    private String jhr1Gx;

    /**
     * 监护人1证件类型
     */
    @Field(type = Keyword)
    private String jhr1Zjlx;

    /**
     * 监护人1证件号码
     */
    @Field(type = Keyword)
    private String jhr1Zjhm;

    /**
     * 婚姻状态 DM_RK_HYZT
     * T_RK.HYZT
     */
    @ShareCode(DM_RK_HYZT)
    @Field(type = Keyword)
    private String marriage;
    /**
     * 出生日期，20210101
     */
    @Field(type = FieldType.Integer)
    private Integer birth;
    /**
     * 默认的房屋名称
     */
    @Field(type = Keyword)
    private String defaultFwmc;

    /**
     * 人户状态 DM_RK_RHZT
     */
    @Field(type = Keyword)
    private Set<String> rhzt = new HashSet<>();
    /**
     * 政治面貌 DM_RK_ZZMM
     */
    @Field(type = Keyword)
    private String zzmm;

    /**
     * 文化程度 DM_RK_WHCD
     */
    @Field(type = Keyword)
    private String whcd;

    /**
     * 人员备注
     */
    @Field(type = Keyword)
    private String bz;


    /**
     * 户籍地详址
     */
    @MultiField(
        mainField = @Field(type = FieldType.Text, analyzer = "my_analyzer"),
        otherFields = @InnerField(suffix = "keyword", type = FieldType.Keyword)
    )
    private String hjdxz;

    /**
     * 地址 id Set
     */
    @Field(type = Keyword)
    private Set<Integer> addressIds = new HashSet<>();

    /**
     * 楼栋id Set
     */
    @Field(type = Keyword)
    private Set<Integer> buildingIds = new HashSet<>();

    /**
     * 房屋 id Set
     */
    @Field(type = Keyword)
    private LinkedHashSet<Integer> roomIds = new LinkedHashSet<>();

    /**
     * 居住地址
     */
    @MultiField(
        mainField = @Field(type = FieldType.Text, analyzer = "my_analyzer"),
        otherFields = @InnerField(suffix = "keyword", type = FieldType.Keyword)
    )
    private LinkedHashSet<String> address = new LinkedHashSet<>();

    /**
     * 网格编号
     */
    @Field(type = Keyword)
    private Set<String> grids = new HashSet<>();

    /**
     * 居民所在的所有查询有效的行政区划
     */
    @Field(type = Keyword)
    private Set<String> regionNos = new HashSet<>();

    /**
     * 标签
     */
    @Field(type = Keyword)
    private Set<String> tags = new HashSet<>();

    /**
     * 医保缴费年
     */
    @Field(type = Keyword)
    private Set<String> ybjfYears = new HashSet<>();

    /**
     * 公安单位
     */
    @Field(type = Keyword)
    private Set<String> gadws = new HashSet<>();

    /**
     * 街路巷
     */
    @Field(type = Keyword)
    private Set<String> jlx;

    /**
     * 门牌号码
     */
    @Field(type = Keyword)
    private Set<String> mphm;


    /**
     * T_RK_RFGL 的最大 ZHHSSJ
     */
    @Field(type = FieldType.Date, format = {}, pattern = "uuuu-MM-dd HH:mm:ss")
    private LocalDateTime zhhssj;

    /**
     * 家庭医生签约-签约标识 0：未签约，1：已签约，按N次导入次数标识第N位，如第一次导入，第二次不导入，则应该为10
     */
    @Field(type = Keyword)
    private String hdSign;

    /**
     * 家庭医生签约-登记状态 DM_HD_QYBS
     */
    @Field(type = Keyword)
    private String hdDjzt;

    /**
     * 婚姻变动日期
     */
    @Field(type = FieldType.Date, format = {}, pattern = "uuuu-MM-dd HH:mm:ss")
    private LocalDateTime hybdrq;

    /**
     * 特长
     */
    @Field(type = Keyword)
    private String tcqk;

    /**
     * 工作单位
     */
    @Field(type = Keyword)
    private String gzdw;

    /**
     * 籍贯
     */
    @Field(type = Keyword)
    private String jg;

    /**
     * 职业，DM_RK_ZY
     */
    @ShareCode(DM_RK_ZY)
    @Field(type = Keyword)
    private String zy;
}
